home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / langs / dl_exsrc.zoo / stristr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-28  |  829 b   |  36 lines

  1. /* from Henry Spencer's stringlib */
  2. /* modified by sb 6/27/94 for case-insensitive comparison */
  3.  
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include "extras.h"
  7.  
  8. /*
  9.  * stristr - find first occurrence of wanted in s, ignoring case
  10.  */
  11.  
  12. char *                /* found string, or NULL if none */
  13. stristr(s, wanted)
  14. const char *s;
  15. const char *wanted;
  16. {
  17.     register const char *scan;
  18.     register size_t len;
  19.     register char firstc;
  20.  
  21.     /*
  22.      * The odd placement of the two tests is so "" is findable.
  23.      * Also, we inline the first char for speed.
  24.      * The ++ on scan has been moved down for optimization.
  25.      */
  26.     firstc = *wanted;
  27.     len = strlen(wanted);
  28.     for (scan = s;
  29.          toupper(*scan) != toupper(firstc) ||
  30.          strnicmp(scan, wanted, len) != 0; ) {
  31.         if (*scan++ == '\0')
  32.             return(NULL);
  33.     }
  34.     return((char *)scan);
  35. }
  36.